package com.atguigu.srb.core.controller.admin;


import com.atguigu.common.exception.Assert;
import com.atguigu.common.result.R;
import com.atguigu.common.result.ResponseEnum;
import com.atguigu.common.util.RegexValidateUtils;
import com.atguigu.srb.base.util.JwtUtils;
import com.atguigu.srb.core.pojo.entity.UserInfo;
import com.atguigu.srb.core.pojo.query.UserInfoQuery;
import com.atguigu.srb.core.pojo.vo.LoginVO;
import com.atguigu.srb.core.pojo.vo.RegisterVO;
import com.atguigu.srb.core.pojo.vo.UserInfoVO;
import com.atguigu.srb.core.service.UserInfoService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 用户基本信息 前端控制器
 * </p>
 *
 * @author zwj
 * @since 2021-10-08
 */
@RestController
@RequestMapping("/admin/core/userInfo")
@Slf4j
//@CrossOrigin
@Api(tags = "用户管理")
public class AdminUserInfoController {
    @Autowired
    private UserInfoService userInfoService;

    @ApiOperation("用户列表")
    @GetMapping("/list/{pageNum}/{limit}")
    public R register(
            @ApiParam(value = "页码",required = true)
            @PathVariable("pageNum") Long pageNum,
            @ApiParam(value = "每页数量",required = true)
            @PathVariable("limit") Long limit,
            @ApiParam(value = "查询条件",required = false)
            UserInfoQuery userInfoQuery
            ){
        Page<UserInfo> page = new Page<>(pageNum, limit);
        IPage pageModel = userInfoService.listPage(page, userInfoQuery);
        return R.ok().data("pageModel",pageModel);
    }

    @ApiOperation("用户锁定或解锁")
    @PutMapping("/lock/{id}/{status}")
    public R register(
            @ApiParam(value = "用户id",required = true)
            @PathVariable("id") Long id,
            @ApiParam(value = "用户状态，1正常，0锁定",required = true)
            @PathVariable("status") Integer status
    ){
        userInfoService.lock(id,status);
        return R.ok().message(status==1?"解锁成功":"锁定成功");
    }


}

